package ch.pizzapp.kurier.view;

import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.EViewGroup;
import org.androidannotations.annotations.ViewById;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import ch.pizzapp.kurier.Constants;
import ch.pizzapp.kurier.R;
import ch.pizzapp.kurier.data.GenarateItem;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.display.SimpleBitmapDisplayer;

/**
 * Shanuka @Cyberlmj 3:08:30 PM Email: shanuka.gayashan@cyberlmj.com
 */
@EViewGroup(R.layout.generator_grid_item)
public class GenarateGridItem extends RelativeLayout {

	@ViewById(R.id.textViewTitle)
	TextView textViewTitle;

	@ViewById(R.id.textViewDescription)
	TextView textViewDescription;

	@ViewById(R.id.textViewPrice)
	TextView textViewPrice;

	private DisplayImageOptions options;
	private ImageLoader imageLoader;

	@ViewById(R.id.imageView)
	ImageView imageView;

	@ViewById(R.id.radioButton)
	CheckBox checkbox;

	GenarateItem genarateItem;

	public GenarateGridItem(final Context context) {
		super(context);

	}

	public GenarateGridItem(final Context context, final AttributeSet attrs) {
		super(context, attrs);
	}

	@AfterViews
	void initAdapter() {
		options = new DisplayImageOptions.Builder()
				.showStubImage(R.drawable.white_background)
				.showImageForEmptyUri(R.drawable.white_background)
				.showImageOnFail(R.drawable.white_background).cacheInMemory(true)
				.cacheOnDisc(true).displayer(new SimpleBitmapDisplayer())
				.build();
		imageLoader = ImageLoader.getInstance();
	}

	public void bind(final GenarateItem genarateItem) {

		this.genarateItem = genarateItem;
		imageLoader.displayImage(Constants.IMAGE_URL + genarateItem.getIcon(),
				imageView, options);
		textViewTitle.setText(genarateItem.getTitle());

		textViewDescription.setText(genarateItem.getDesc());

		textViewPrice.setText(genarateItem.getPrice());

		checkbox.setOnCheckedChangeListener(new OnCheckedChangeListener() {

			@Override
			public void onCheckedChanged(CompoundButton buttonView,
					boolean isChecked) {

//				if (isChecked) {
//					genarateItem.setIsSelceted(true);
//				} else {
//					genarateItem.setIsSelceted(false);
//				}
			}
		});

	}
}
